function CLim = newclim(BeginSlot,EndSlot,CDmin,CDmax,CmLength)

%                Convert slot number and range
%                to percent of colormap

% To calculate the new values for CLim, you need to know:
%  - The total length of the colormap (CmLength)
%  - The beginning colormap slot to use for each axes (BeginSlot)
%  - The ending colormap slot to use for each axes (EndSlot)
%  - The minimum and maximum CData values of the graphic objects 
%    contained in the axes. That is, the values of the axes CLim 
%    property determined by MATLAB when CLimMode is auto 
%    (CDmin and CDmax). 


PBeginSlot    = (BeginSlot - 1) / (CmLength - 1);
PEndSlot      = (EndSlot - 1) / (CmLength - 1);
PCmRange      = PEndSlot - PBeginSlot;

%                Determine range and min and max 
%                of new CLim values

DataRange     = CDmax - CDmin;
ClimRange     = DataRange / PCmRange;
NewCmin       = CDmin - (PBeginSlot * ClimRange);
NewCmax       = CDmax + (1 - PEndSlot) * ClimRange;
CLim          = [NewCmin,NewCmax];

